package qj.tool.jna;

import com.sun.jna.Native;
import com.sun.jna.Pointer;
import com.sun.jna.Structure;
import com.sun.jna.examples.win32.W32API;
import com.sun.jna.ptr.PointerByReference;

public interface Netapi32 extends W32API {
	int MAX_PREFERRED_LENGTH = -1;
	int FILTER_NORMAL_ACCOUNT = 2;
	int ERROR_MORE_DATA = 234;
	int NERR_SUCCESS = 0;
	
	Netapi32 INSTANCE = (Netapi32) Native.loadLibrary("netapi32", Netapi32.class, DEFAULT_OPTIONS);
	int NetUserEnum(
			String servername,
			int level,
			int filter,
			PointerByReference bufptr,
			int prefmaxlen,
			int[] entriesread,
			int[] totalentries,
			int[] resume_handle
	);
	
	int NetApiBufferFree(Pointer buffer);
	
	int NetLocalGroupEnum(
			String servername,
			int level,
			PointerByReference bufptr,
			int prefmaxlen,
			int[] entriesread,
			int[] totalentries,
			int[] resume_handle
	);
	int NetLocalGroupGetMembers(
			String servername,
			String localgroupname,
			int level,
			PointerByReference bufptr,
			int prefmaxlen,
			int[] entriesread,
			int[] totalentries,
			int[] resume_handle
	);
	class LOCALGROUP_INFO_0 extends Structure {
		public String lgrpi0_name;
		public static LOCALGROUP_INFO_0 createFrom( byte[] data )
		{
			LOCALGROUP_INFO_0 s = new LOCALGROUP_INFO_0();
			s.allocateMemory(data.length); 
			s.getPointer().write(0, data, 0, data.length); 
			s.read(); 
			return s; 
		}
	}
	class LOCALGROUP_INFO_1 extends Structure {
		public String lgrpi1_name;
		public String lgrpi1_comment;

		public static LOCALGROUP_INFO_1 createFrom( byte[] data )
		{
			LOCALGROUP_INFO_1 s = new LOCALGROUP_INFO_1();
			s.allocateMemory(data.length); 
			s.getPointer().write(0, data, 0, data.length); 
			s.read();
			return s; 
		}
	}

	class LOCALGROUP_MEMBERS_INFO_2 extends Structure {
		public int lgrmi2_sid;
		public int lgrmi2_sidusage;
		public String lgrmi2_domainandname;
		public static LOCALGROUP_MEMBERS_INFO_2 createFrom( byte[] data )
		{
			LOCALGROUP_MEMBERS_INFO_2 s = new LOCALGROUP_MEMBERS_INFO_2();
			s.allocateMemory(data.length); 
			s.getPointer().write(0, data, 0, data.length); 
			s.read(); 
			return s; 
		}
	}
	
	class USER_INFO_0 extends Structure {
		public String usri0_name;
		public static USER_INFO_0 createFrom( byte[] data )
		{
			USER_INFO_0 s = new USER_INFO_0();
			s.allocateMemory(data.length); 
			s.getPointer().write(0, data, 0, data.length); 
			s.read(); 
			return s; 
		}
	}
	
	long NetApiBufferFree(long buffer);
}
